package com.ck.hxc.controller;

import com.alibaba.fastjson2.JSONObject;
import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
import io.github.pigmesh.ai.deepseek.core.chat.*;
import lombok.Builder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author hxc
 * @since 2025/2/19 13:48
 */
@RestController
@RequestMapping("/deepseekTest")
@Builder
public class DeepSeekTestController {

    @Autowired
    private DeepSeekClient deepSeekClient;

    @GetMapping("/test1")
    public String test1() {
        return "你好";
    }

    @GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> chat(String prompt) {
        return deepSeekClient.chatFluxCompletion(prompt);
    }

    @GetMapping(value = "/chat/advanced", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> chatAdvanced(String prompt) {
        ChatCompletionRequest request = ChatCompletionRequest.builder()
        .model("yf") //选择模型
        .addUserMessage(prompt)//添加用户消息
        .addAssistantMessage("上轮结果")//# 添加助手消息
        .addSystemMessage("你是一个专业的助手")//# 添加系统消息
        .maxTokens(3000)//设置最大生成 token 数
        //.responseFormat(ResponseFormatType.TEXT)//可选：设置响应格式
        //.tools()//可选：工具调用
        .build();
        return deepSeekClient.chatFluxCompletion(request);
    }

    @GetMapping(value = "/sync/chat")
    public ChatCompletionResponse syncChat(String prompt) {
    ChatCompletionRequest request = ChatCompletionRequest.builder()
    .model("32bq4")  //动态设置模型
    .addUserMessage(prompt).build();

    return deepSeekClient.chatCompletion(request).execute();
    }

}
